# -*- coding: UTF-8 -*- #
"""
-------真正的勇士， 敢于直面惨淡的Warning、 敢于正视淋漓的Error-----
@author : 贾鹏博
@file : base_page.py
@time : 2022/6/11 17:28
"""

import time
from appium.webdriver.webdriver import WebDriver


# 基类  driver  find_element  click   send_keys
class BasePage:

    def __init__(self, driver: WebDriver = None):
        self.driver = driver

    def find(self, by, locator):
        return self.driver.find_element(by, locator)

    def find_and_click(self, by, locator):
        self.find(by, locator).click()

    def find_and_send(self, by, locator, text):
        self.find(by, locator).send_keys(text)

    # 获取 text 属性
    def find_and_gettext(self, by, locator):
        return self.find(by, locator).text

    # 截图
    def screenshot(self, filename):
        self.driver.save_screenshot(filename)

    def get_time(self):
        t = time.localtime(time.time())
        cur_time = time.strftime("%Y-%m-%d_%H_%M_%S", t)
        return cur_time
